<?php

abstract class Products_Validator_ProductAbstract extends Zend_Validate_Abstract
{
    
    /**
     * Error constants
     */ 
    const ERROR_NO_PRODUCT_FOUND = 'noproductFound';  
    const ERROR_PRODUCT_FOUND = 'productFound';  
    
    /**
     * @var array Message templates
     */    
    protected $_messageTemplates = array
    (
        self::ERROR_NO_PRODUCT_FOUND => '%value% - нет такого продукта в БД', 
        self::ERROR_PRODUCT_FOUND    => '%value% - продукт уже сохранен в БД',
    );
    
    
    
    /**
     * Run query and returns matches, or null if no matches are found.
     *
     * @param  String $value
     * @return Array when matches are found.
     */ 
    protected function _query($value) 
    {
        $query = Doctrine_Query::create()
             ->select('COUNT(*)')
             ->from('Products')
             ->where('name = ?', $value)
             ->limit(1)
             ;
        
        return $query->execute(array(), Doctrine::HYDRATE_SINGLE_SCALAR) > 0;
    } 
    
}